package com.ruoyi.web.controller.frontierEvent;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.frontierEvent.bo.TAttachAddBo;
import com.ruoyi.system.frontierEvent.bo.TAttachEditBo;
import com.ruoyi.system.frontierEvent.bo.TAttachQueryBo;
import com.ruoyi.system.frontierEvent.service.ITAttachService;
import com.ruoyi.system.frontierEvent.vo.TAttachVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 附件Controller
 * 
 * @author ruoyi
 * @date 2021-05-19
 */
@Api(value = "附件控制器", tags = {"附件管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/frontierEvent/attach")
public class TAttachController extends BaseController {

    private final ITAttachService iTAttachService;

    /**
     * 查询附件列表
     */
    @ApiOperation("查询附件列表")
    @PreAuthorize("@ss.hasPermi('frontierEvent:attach:list')")
    @GetMapping("/list")
    public TableDataInfo<TAttachVo> list(TAttachQueryBo bo) {
        startPage();
        List<TAttachVo> list = iTAttachService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出附件列表
     */
    @ApiOperation("导出附件列表")
    @PreAuthorize("@ss.hasPermi('frontierEvent:attach:export')")
    @Log(title = "附件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TAttachVo> export(TAttachQueryBo bo) {
        List<TAttachVo> list = iTAttachService.queryList(bo);
        ExcelUtil<TAttachVo> util = new ExcelUtil<TAttachVo>(TAttachVo.class);
        return util.exportExcel(list, "附件");
    }

    /**
     * 获取附件详细信息
     */
    @ApiOperation("获取附件详细信息")
    @PreAuthorize("@ss.hasPermi('frontierEvent:attach:query')")
    @GetMapping("/{id}")
    public AjaxResult<TAttachVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iTAttachService.queryById(id));
    }

    /**
     * 新增附件
     */
    @ApiOperation("新增附件")
    @PreAuthorize("@ss.hasPermi('frontierEvent:attach:add')")
    @Log(title = "附件", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TAttachAddBo bo) {
        return toAjax(iTAttachService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改附件
     */
    @ApiOperation("修改附件")
    @PreAuthorize("@ss.hasPermi('frontierEvent:attach:edit')")
    @Log(title = "附件", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TAttachEditBo bo) {
        return toAjax(iTAttachService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除附件
     */
    @ApiOperation("删除附件")
    @PreAuthorize("@ss.hasPermi('frontierEvent:attach:remove')")
    @Log(title = "附件" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iTAttachService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
